#include <iostream>
#include <stdio.h>
using namespace std;

template <typename T>
class A{    
public:
    A(T a,T b);
    A operator+(A &a1);
    void print();

//友元函数重载<< 
friend ostream & operator<<(ostream &out,A &a2)
{
    out<<a2.a<<" + "<<a2.b<<"i"<<endl;
    return out;
}
    
private:
    T a;
    T b;   
};

//模板类外初始化构造函数
template <typename T>
A<T>::A(T a,T b)
{
    this->a=a;
    this->b=b;
}
    
template <typename T>
void A<T>::print()
{
    printf("hello\n"); 
}

template <typename T>
A<T> A<T>::operator+(A<T> &a1)
{
    A temp(this->a+a1.a,this->b+a1.b);
    return temp;
}  

int main()
{
    A<int> aa(1,2);
    A<int> bb(2,3);
    aa.print();
    aa=aa+bb;
    cout<<aa;
   
    return 0;
}
